﻿using ShortcutMenu.Manager;
using ShortcutMenu.Render;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace ShortcutMenu
{
    public class MenuApplication
    {
        private static MenuApplication menuApplication;

        private MainWindow _mainWindow;

        private Dictionary<Type, ManagerBase> _managers = new();

        public MenuApplication(MainWindow mainWindow)
        {
            menuApplication = this;
            _mainWindow = mainWindow;

            CreateManager();
        }

        public static T GetManager<T>() where T : ManagerBase
        {
            return (menuApplication._managers[typeof(T)] as T)!;
        }

        public static T GetRender<T>()
            where T : RenderBase
        {
            return GetManager<ReaderManager>().GetReader<T>();
        }

        public static MainWindow GetMainWondw()
        {
            return menuApplication._mainWindow;
        }



        #region initial
        private void CreateManager()
        {
            var ass = Assembly.GetAssembly(typeof(ManagerBase))!.GetTypes();
            _managers = Reflection.Create<ManagerBase>(ass);

            foreach (var type in _managers)
            {
                type.Value.initialize();
            }
        }

        #endregion
    }
}
